package flyweight_pattern;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author liwuji
 * @date 2023/12/26
 * @desc
 **/
public class ShapeFactory {
    private static final ConcurrentHashMap<String, Shape> circleMap = new ConcurrentHashMap<>();

    public static Shape getCircle(String color) {
        Circle circle = (Circle) circleMap.get(color);
        if (circle == null) {
            circle = new Circle(color);
            circleMap.put(color, circle);
            System.out.println("Creating circle of color : " + color);
        }
        return circle;
    }
}
